package com.vote.controllers;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;

import com.vote.model.User;
import com.vote.services.UserService;


public class UserController {

    /**
     * Logger for this class
     */
    private static final Logger logger = Logger.getLogger(UserController.class);
    
    @Autowired
    UserService userService;
    
    public String index(){
        return "register";
    }
    
    public String register(User user){
        int id = -1;
        try {
            id = userService.insertUser(user);
        } catch (Exception e) {
            logger.info("insert user fail!\n", e);
        }
        logger.debug("add new user : user name = " + user.getUserName() + "; user password = " + user.getUserPassword() + "; user email = " + user.getUserEmail());
        return "@"+id;
    }
}
